<template>
  <view class="my u-skeleton">
    <!-- #ifdef APP-PLUS -->
    <view class="nav-Height"></view>
    <!-- #endif -->
    <view class="top u-skeleton-rect">
      <view class="left">
        <u-avatar :src="$util.img(info ? info.avatar : '')"></u-avatar>
        <view class="l-right" v-if="info">
          <view class="name">{{ info.nickname }} <text style="margin-left: 30rpx;font-size: 26rpx;">ID：{{ info.uid }}</text>
          </view>
          <view class="id">
            <text>邀请码：{{ info.code }}</text>
            <image :src="$util.img('/static/img/my/复制.png')" mode="" @click="copy(info.code.toString())">
            </image>
          </view>
        </view>
        <view class="l-right-hover" v-else @click="$util.redirectTo('/pages/login/login')">请登录</view>
      </view>
      <image class="right" :src="$util.img('/static/img/my/设置.png')" mode=""
        @click="$util.redirectTo('/pages/my/setup')"></image>
    </view>
    <view class="info u-skeleton-rect" @click="$util.redirectTo('/pages/my/grade')">
      <image :src="$util.img('/static/img/my/等级.png')" mode=""></image>
      <view class="box">
        <view class="b-box">
          <image class="b-left" :src="$util.img('/static/img/my/1.png')" mode=""></image>
          <view class="b-right">
            <view class="br-top">我的达人等级</view>
            <view class="br-bottom">{{ info ? info.level_name : 0 }}</view>
          </view>
        </view>
        <view class="info-btn">查看详情</view>
      </view>
    </view>
    <view class="module u-skeleton-rect">
      <view class="o-title">我的订单</view>
      <view class="m-box m-box-top">
        <view class="item" v-for="(item, index) in orderList" :key="index" @click="gotolink({
          type: 'order',
          index
        })">
          <image class="demo-img" :src="$util.img(item.src)" mode="widthFix"></image>
          <view class="tips">{{ item.title }}</view>
        </view>
      </view>
    </view>
    <view class="invite u-skeleton-rect" @click="$util.redirectTo('/pages/tidalcard/myfriend')">
      <image class="i-image" :src="$util.img('/static/img/my/邀请-1.png')" mode="widthFix"></image>
      <view class="i-box">
        <view class="i-top">
          <view class="it-left">
            <text>邀请好友</text>
            <image :src="$util.img('/static/img/my/奖励.png')" mode="widthFix"></image>
          </view>
          <view class="it-right">
            <text class="txt">详情</text>
            <u-icon name='arrow-right' color='rgba(255,255,255,.4)' size='24'></u-icon>
          </view>
        </view>
        <view class="i-bottom">
          <view class="item">
            <view class="it-txt" style="margin-bottom: 10rpx;">{{ info ? info.invite_num : 0 }}个</view>
            <view class="it-txt">邀请人数</view>
          </view>
          <view class="item">
            <view class="it-txt" style="margin-bottom: 10rpx;">{{ info ? info.valid_num : 0 }}个</view>
            <view class="it-txt">有效人数</view>
          </view>
          <u-button class="btn-primary u-skeleton-rect" ripple-bg-color="rgba(0,0,0,.4)"
            @click.stop="$util.redirectTo('/pages/my/invite')" :ripple="true">邀请好友</u-button>
        </view>
      </view>
    </view>
    <view class="module u-skeleton-rect">
      <view class="o-title">常用功能</view>
      <view class="m-box m-box-bottom" v-if="info">
        <view class="item item-bottom" v-for="(item, index) in functionList" :key="index" @click="gotolink({
          type: 'function', item
        })" v-show="!item.type || item.type == 'kf' || (item.type == 'dz' && info.dz_status == 2)">
          <image class="demo-img" :src="$util.img(item.src)" mode="widthFix"></image>
          <view class="tips">{{ item.title }}</view>
        </view>
      </view>
    </view>
    <view style="padding: 20rpx 0;">
      <view style="text-align: center;color: rgba(0,0,0,.4);margin-top:10rpx;font-size: 24rpx;">技术支持 @ 极客科技</view>
    </view>
    <diy-tabbar current="my"></diy-tabbar>
    <diy-customer :show="customerShow" @close="customerShow = false"></diy-customer>
    <!-- 提醒登录弹窗 -->
    <diy-login-tips :show='loginShow' @close="loginShow = false" @callback='() => loginShow = false'></diy-login-tips>
    <u-skeleton :loading="loding" :animation="true" bgColor="#FFF"></u-skeleton>
  </view>
</template>

<script>
import diyCustomer from "../../components/diy-customer/diy-customer.vue"
export default {
  components: {
    diyCustomer
  },
  data() {
    return {
      //弹窗打开
      loginShow: false,
      // 客服弹窗打开
      customerShow: false,
      // 首次进入加载
      loding: true,
      // 订单导航
      orderList: [{
        title: '我的订单',
        src: '/static/img/my/1-1.png'
      }, {
        title: '待支付',
        src: '/static/img/my/2.png'
      }, {
        title: '待发货',
        src: '/static/img/my/1-1.png'
      }, {
        title: '已完成',
        src: '/static/img/my/3.png'
      }, {
        title: '已取消',
        src: '/static/img/my/4.png'
      }],
      // 功能导航
      functionList: [{
        title: '我的资产',
        src: '/static/img/my/记录.png',
        link: '/pages/my/myAssets'
      },
      {
        title: '客服',
        src: '/static/img/my/公告.png',
        link: '',
        type: 'kf'
      },
      {
        title: '邀请好友',
        src: '/static/img/my/邀请.png',
        link: '/pages/my/invite'
      },
      {
        title: '社交信息',
        src: '/static/img/my/藏品.png',
        link: '/pages/tidalcard/myOcializeInformation'
      },
      {
        title: '我的认证',
        src: '/static/img/my/认证.png',
        link: '/pages/my/authentication'
      }, {
        title: '收货地址',
        src: '/static/img/my/地址.png',
        link: '/pages/my/address'
      }, {
        title: '关于我们',
        src: '/static/img/my/关于我们.png',
        link: '/pages/my/about'
      }, {
        title: '帮助中心',
        src: '/static/img/my/公告.png',
        link: '/pages/my/notice'
      }, {
        title: '卡柜',
        src: '/static/img/my/卡柜.png',
        link: '/pages/my/cardCabinet'
      }, {
        title: '店长',
        src: '/static/img/my/店长-1.png',
        link: '/pages/my/manager',
        type: 'dz'
      }
      ],
      //个人详情数据
      info: null
    }
  },
  onLoad() {
    //#ifdef APP
    uni.hideTabBar()
    //#endif
  },
  onShow() {
    if (!uni.getStorageSync('token')) this.loginShow = true
    this.$nextTick(() => {
      this.getinfo();
    })
  },
  methods: {
    //获取当前个人数据
    getinfo() {
      setTimeout(() => {
        this.loding = false;
      }, 1000)
      this.$http.asyncSendrequest({
        url: '/profile/userInfo',
        success: res => {
          if (res.code == '0') {
            if (Object.prototype.toString.call(res.data) != '[object Array]') {
              this.info = res.data;
              this.loding = false;
            }
          }
        }
      })
    },
    // 复制数据
    copy(value) {
      this.$util.copy(value, (res) => {
        console.log("zhegn1")
      })
    },
    // 前往页面
    gotolink(params) {
      console.log("数据", params)
      switch (params.type) {
        case 'order':
          this.$util.redirectTo('/pages/order/order', params.index)
          break;
        case 'function':
          if (params.item.type == 'kf') {
            this.customerShow = true;
          } else this.$util.redirectTo(params.item.link)
          break;
        default:
          break;
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.my {
  width: 100%;
  min-height: 100vh;
  padding-top: 50rpx;
  padding-bottom: 140rpx;

  .top {
    margin: 0 30rpx;
    display: flex;
    align-items: center;
    justify-content: space-between;

    .left {
      display: flex;
      align-items: center;

      .l-right {
        margin-left: 30rpx;

        .name {
          font-size: 32rpx;
          font-family: PingFang SC;
          font-weight: bold;
          color: #292929;
        }

        .id {
          font-size: 24rpx;
          font-family: PingFang SC;
          font-weight: 500;
          color: #292929;
          margin-top: 16rpx;
          display: flex;
          align-items: center;

          image {
            width: 30rpx;
            height: 30rpx;
            margin-left: 6rpx;
          }
        }

      }

      .l-right-hover {
        font-size: 32rpx;
        font-weight: bold;
        margin-left: 30rpx;
      }
    }

    .right {
      width: 45rpx;
      height: 45rpx;
    }
  }

  .info {
    margin: 38rpx 30rpx 20rpx;
    height: 135rpx;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: relative;

    image {
      width: 100%;
      height: 100%;
    }

    .box {
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      padding: 0 44rpx 0 34rpx;
      display: flex;
      align-items: center;
      justify-content: space-between;

      .b-box {
        display: flex;
        align-items: center;

        .b-left {
          width: 120rpx;
          height: 120rpx;
          margin-right: 34rpx;
        }

        .b-right {
          .br-top {
            font-size: 24rpx;
            font-family: PingFang SC;
            font-weight: bold;
            color: #FFFFFF;
            margin-bottom: 10rpx;
          }

          .br-bottom {
            font-size: 26rpx;
            font-family: PingFang SC;
            font-weight: bold;
            color: #FFF09C;
          }
        }
      }

      .info-btn {
        width: 135rpx;
        height: 40rpx;
        border: 1rpx solid #FFFFFF;
        border-radius: 40rpx;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 24rpx;
        font-family: PingFang SC;
        font-weight: 500;
        color: #FFFFFF;
      }
    }
  }

  .module {
    min-height: 270rpx;
    background: #FFFFFF;
    border-radius: 20rpx;
    margin: 0 30rpx;
    padding: 30rpx 0 0;

    .o-title {
      margin: 0 40rpx 47rpx;
      font-size: 26rpx;
      font-family: PingFang SC;
      font-weight: bold;
      color: #000000;
    }

    .m-box {
      margin: 0 40rpx;
      display: flex;
      flex-wrap: wrap;

      .item {
        width: 100rpx;
        text-align: center;
        margin: 0 56rpx 44rpx 0;

        .demo-img {
          width: 65rpx;
        }

        .tips {
          font-size: 24rpx;
          font-family: PingFang SC;
          font-weight: 500;
          color: #000000;
        }
      }

      .item:nth-child(4n) {
        margin-right: 0;
      }

      .item-bottom {
        .demo-img {
          width: 50rpx;
        }
      }
    }

    .m-box-top {
      .item {
        margin-right: 26rpx;
      }

      .item:nth-child(4n) {
        margin-right: 26rpx;
      }

      .item:nth-child(5n) {
        margin-right: 0;
      }
    }

    .m-box-bottom {
      .item {
        margin-right: 58rpx;
        width: 108rpx;

        .demo-img {
          width: 64rpx;
        }

        .tips {
          font-size: 26rpx;
          font-family: PingFang SC;
          font-weight: 500;
          color: #000000;
        }
      }
    }
  }

  .invite {
    margin: 20rpx 30rpx;
    height: 212rpx;
    position: relative;

    image {
      width: 100%;
      height: 100%;
    }

    .i-box {
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;

      .i-top {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 18rpx 42rpx;
        box-sizing: border-box;

        .it-left {
          font-size: 26rpx;
          font-family: PingFang SC;
          font-weight: bold;
          color: #FFFFFF;
          display: flex;
          align-items: center;

          image {
            width: 105rpx;
            margin-left: 14rpx;
            margin-top: 4rpx;
          }
        }

        .it-right {
          font-size: 24rpx;
          font-family: PingFang SC;
          font-weight: bold;
          color: #FFFFFF;
          opacity: 0.6;

          text {
            margin-right: 20rpx;
          }
        }
      }

      .i-bottom {
        height: calc(100% - 80rpx);
        padding: 0 30rpx 0 42rpx;
        box-sizing: border-box;
        display: flex;
        align-items: center;
        justify-content: space-between;

        .item {
          .it-txt {
            font-size: 24rpx;
            font-family: PingFang SC;
            font-weight: bold;
            color: #292929;
          }
        }

        .btn-primary {
          height: 60rpx;
          background: #292929;
          border-radius: 10rpx;
          text-align: center;
          line-height: 96rpx;
          font-size: 26rpx;
          font-family: PingFang SC;
          color: #FFFFFF;
          margin: 0;
        }
      }
    }
  }
}
</style>